/*
 * WorkConnectApi.h
 *
 *  Created on: 2016-2-24
 *      Author: root
 */

#ifndef WORKCONNECTAPI_H_
#define WORKCONNECTAPI_H_
#include"PublicConfig.h"
#include"PublicIPTool.h"
typedef struct _CONNECTKEY{
char       IP[40];//IP
uint16_t   Port;//采集端口
bool operator<(struct _CONNECTKEY const &other)const{
    if(Port<other.Port)
        return true;
    if(Port==other.Port){
        return strcmp(IP, other.IP)<0;
    }
    return false;
}
}CONNECTKEY;
typedef struct _CONNECTVAL{
int time;//-1连接拒绝，0超时，连接耗时
int tcping;//连接耗时或拒绝耗时，0超时
}CONNECTVAL;
#if USE_PUBLIC_CONNECT
typedef std::map<CONNECTKEY,CONNECTVAL>         MAPCONNECTRESULTINFO; //IP IP状态
typedef std::map<CONNECTKEY,int>                MAPCONNECTRESULTINFOS; //IP IP状态,给UDP用
typedef std::set<CONNECTKEY>                    SETCONNECTINFO;       //存储列接队列
typedef std::map<std::string,SETCONNECTINFO>    MAPCONNECTINFO;       //存储列接队列
//初始化必备函数
void InitOpenMAX();
//探测队列,最大等待数
MAPCONNECTRESULTINFO GetConnectInfoByIPList(SETCONNECTINFO IPList,size_t MaxWaitList,int MaxTimeOut,const char*SRC_IP);
//本地IP都过一遍
MAPCONNECTRESULTINFO GetConnectInfoByIPListWithLocal(SETCONNECTINFO IPList,size_t MaxWaitList,int MaxTimeOut);
//返回值说明-1连接拒绝，0超时
//最大等待队列长度，最大超时时长单位s
MAPCONNECTRESULTINFO GetConnectInfoByIPMAPList(MAPCONNECTINFO IPList,size_t MaxWaitList,int MaxTimeOut);
//通过IP列表和端口类表获取结果，bReuse 1，每次都重新获取 0成功一次后移除
MAPCONNECTRESULTINFO GetTcpingByIPList(SETIPLIST IPList,SETPORTLIST PortList,int bReuse);
//打印状态
void ShowConnectStatusInfo(MAPCONNECTRESULTINFO IPList,bool bSave,bool bShow);

//UDP端口探测相关
#if USE_PUBLIC_UDP
typedef struct _UDPFLAG{
int    SendTimes;//总发送次数
int    PerTime;//发送间隔us
int    PerNum;//单次发送个数
int    PerListTime;//构建队列间隔ms
char   SrcIP[40];//源IP
}UDPFLAG;
//初始化PING风格
UDPFLAG InitUdpFlag();
//显示PING风格
void ShowUdpFlag(UDPFLAG flag,size_t num);
MAPCONNECTRESULTINFOS GetUdpInfoByIPList(SETCONNECTINFO IPList,UDPFLAG flag);
MAPCONNECTRESULTINFOS GetUdpInfoByIPListWithLocal(SETCONNECTINFO IPList,UDPFLAG flag);
MAPCONNECTRESULTINFOS GetUdpingByIPList(SETIPLIST IPList,SETIDLIST PortList,int bReuse);
//打印信息
void ShowUDPStatusInfo(MAPCONNECTRESULTINFOS IPList,bool bSave,bool bShow);
#endif
#endif /* WORKCONNECTAPI_H_ */
#endif
